package com.service.impl;

import com.entity.BGoods;
import com.entity.FCartGoods;
import com.entity.table.FCartGoodsTableDef;
import com.mapper.FCartGoodsMapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.service.FCartGoodsService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class FCartGoodsServiceImpl extends ServiceImpl<FCartGoodsMapper, FCartGoods> implements FCartGoodsService {
    public BGoods getTotalPriceByGood(int cartId, BGoods good){
        FCartGoods fCartGoods = this.queryChain().where(FCartGoodsTableDef.F_CART_GOODS.CART_ID.eq(cartId))
                .and(FCartGoodsTableDef.F_CART_GOODS.GOODS_ID.eq(good.getId())).one();
        good.setNum(fCartGoods.getNum());
        BigDecimal _totalPrice = good.getPrice().multiply(new BigDecimal(fCartGoods.getNum()));
        good.setTotalPrice(_totalPrice);
        return good;
    }
}
